package admin

import (
	auto "beergo/app/hr/auto/controller"
	"beergo/app/hr/conf"
	"beergo/app/hr/models"
	"beergo/conf/const/code"
	"beergo/lib/tool"
	"github.com/beego/beego/v2/server/web"
)

type ProfileEduAdminController struct {
	auto.ProfileEduController
}

func init() {
	web.Router(conf.UrlPrefix + "/ProfileEdu/:id", 		&ProfileEduAdminController{}, "*:GetAction")
	web.Router(conf.UrlPrefix + "/ProfileEdu/info", 		&ProfileEduAdminController{}, "*:InfoAction")
	web.Router(conf.UrlPrefix + "/ProfileEdu/scan", 		&ProfileEduAdminController{}, "*:ScanAction")
	web.Router(conf.UrlPrefix + "/ProfileEdu/list", 	    &ProfileEduAdminController{}, "*:ListAction")
	web.Router(conf.UrlPrefix + "/ProfileEdu/update", 	&ProfileEduAdminController{}, "*:UpdateAction")
	web.Router(conf.UrlPrefix + "/ProfileEdu/create", 	&ProfileEduAdminController{}, "*:CreateAction")
	web.Router(conf.UrlPrefix + "/ProfileEdu/copy", 	    &ProfileEduAdminController{}, "*:CopyAction")
	web.Router(conf.UrlPrefix + "/ProfileEdu/edit", 	    &ProfileEduAdminController{}, "*:EditAction")
	web.Router(conf.UrlPrefix + "/ProfileEdu/delete", 	&ProfileEduAdminController{}, "*:DeleteAction")
	web.Router(conf.UrlPrefix + "/ProfileEdu/:id/:field", &ProfileEduAdminController{}, "*:SonsAction")
	web.Router(conf.UrlPrefix + "/ProfileEdu/choice", &ProfileEduAdminController{}, "*:ChoiceAction")
	web.Router(conf.UrlPrefix + "/ProfileEdu/category", &ProfileEduAdminController{}, "*:CategoryAction")
}
//func (this *ProfileEduAdminController) Prepare() {}
func (this *ProfileEduAdminController) ListAction() {

	user:=this.GetUser()
	pm:=GetProfileMain(user.Id)
	if this.QueryBuilder.Conditions == nil {
		this.QueryBuilder.Conditions = make(map[string]interface{})
	}
	this.QueryBuilder.Conditions["main"]=pm.Id
	lists, err := this.Repository.GetList(this.QueryBuilder)
	if err != nil {
		this.StopError(code.Error, "系统错误", err.Error())
	}

	this.JsonData["lists"] = lists
	this.JsonData["query"] = this.QueryBuilder.FeedBack()
	this.ReturnSuccess("OK", this.JsonData)
}
//func (this *ProfileEduAdminController) GetAction() {}
//func (this *ProfileEduAdminController) InfoAction() {}
//func (this *ProfileEduAdminController) ScanAction() {}
func (this *ProfileEduAdminController) CreateAction() {
	entity := this.Model.New()
	_, err := this.JsonParseModel(entity)
	this.AnaliseErrors(err)
	user:=this.GetUser()
	pm:=GetProfileMain(user.Id)
	entity.Main = &pm
	_, errSave := entity.Save()
	this.AnaliseErrors(errSave)
	this.FillM2M(entity)
	this.ReturnSuccess("OK", entity.Id)
}

func GetProfileMain(uid int) models.ProfileMain {
	rep:=models.ProfileMainRepository{}
	find:=rep.FindOneBy(tool.M{"createBy":uid},[]string{"-id"})
	return find
}
//func (this *ProfileEduAdminController) UpdateAction() {}
//func (this *ProfileEduAdminController) CopyAction() {}
//func (this *ProfileEduAdminController) DeleteAction() {}
//func (this *ProfileEduAdminController) EditAction() {}
//func (this *ProfileEduAdminController) SonsAction() {}
//func (this *ProfileEduAdminController) ChoiceAction() {}
//func (this *ProfileEduAdminController) CategoryAction() {}
